package info.nightbrest.agt.shared.rpc;

import com.google.gwt.json.client.JSONObject;
import info.nightbrest.agt.client.AgtDispatcher;

public class SimpleStatus implements AgtDispatcher.Result.Status
{
	protected String value = null;
	protected String message = null;

	public SimpleStatus(String value)
	{
		this.value = value;
	}

	public SimpleStatus(String value, String message)
	{
		this.value = value;
		this.message = message;
	}

	@Override
	public String getValue()
	{
		return value != null ? value.toLowerCase() : null;
	}

	@Override
	public String getMessage()
	{
		return message;
	}

	public static SimpleStatus fromJSON(JSONObject o)
	{
		return new SimpleStatus(
				(o.containsKey("status")  ? o.get("status").isString().stringValue() : null),
				(o.containsKey("message") ? o.get("message").isString().stringValue() : null)
		);
	}

	@Override
	public boolean isOk()
	{
		return (getValue().compareToIgnoreCase(AgtDispatcher.Result.Status.ACTION_STATUS_OK) == 0);
	}
}
